﻿using MaterialDesignThemes.Wpf;
using Prism.Commands;
using StarryEdge.Core.Enums;
using StarryEdge.Core.Manager;
using StarryEdge.Core.Models;
using StarryEdge.Core.Models.Interact;
using StarryEdge.Parameter;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace StarryEdge.Menu.Device.ViewModels.Dialog
{
    public class DeviceModifyPopupDialog<T>
    {
        public DeviceInfoModel DCModel { get; set; }
        public ObservableCollection<string> ServiceNameList { get; set; }

        public IEnumerable<DeviceTypes> Foods
        {
            get
            {
                foreach (DeviceTypes c in (DeviceTypes[])Enum.GetValues(typeof(DeviceTypes)))
                {
                    yield return c;
                }
            }
        }
        public IEnumerable<int> IndexList
        {
            get
            {
                for (int i = 0; i < 33; i++)
                {
                    yield return i;
                }
            }
        }
        private IObjectManager _objectManager;
        private DeviceInfoManage _deviceInfoManage;
        public DeviceModifyPopupDialog(DeviceInfoModel model, 
            ObservableCollection<ScanSignalModel<int>> scanIntSignals, 
            ObservableCollection<ScanSignalModel<string>> scanStringSignals, 
            IObjectManager objectManager, 
            DeviceInfoManage deviceInfo)
        {
            _deviceInfoManage = deviceInfo;
            DCModel = model;
            _objectManager = objectManager;
            ServiceNameList = new ObservableCollection<string>();
            foreach (var item in scanIntSignals)
            {
                ServiceNameList.Add(item.Name);
            }
            foreach (var item in scanStringSignals)
            {
                ServiceNameList.Add(item.Name);
            }
        }

        public IEnumerable<string> TaskList
        {
            get => _objectManager.GetTaskNames();
        }

        public DelegateCommand<string> SaveDelete => new DelegateCommand<string>(sender =>
        {
            if (sender != null)
            {
                switch (sender)
                {
                    case "删除":
                        _deviceInfoManage.DeviceInfos.Remove(DCModel);
                        break;
                }
                _deviceInfoManage.Save();
                if (DialogHost.IsDialogOpen(PopUpTypes.Global.ToString())) { DialogHost.Close(PopUpTypes.Global.ToString()); }
            }
        });
    }
}
